#include <iostream>
#include <string>
#include <memory>

//抽象的产品类
class Computer
{
public:
    void Scree(const std::string& scree)
    {
        _scree = scree;
    }
    void Board(const std::string& board)
    {
        _board = board;
    }
    virtual void Os() = 0;

    void Display()
    {
        std::cout << _scree << ":" << _board << ":" << _os << std::endl;
    }

protected:
    std::string _scree; //显示器
    std::string _board; //主板
    std::string _os; //操作系统
};

//产品的具体类
class HuaweiComputer : public Computer
{
public:
    void Os() override
    {
        _os = "鸿蒙";
    }
};

//建造者的抽象类
class Builder
{
public:
    virtual void BuildScree(const std::string &scree) = 0;
    virtual void BuildBoard(const std::string &board) = 0;
    virtual void BuildOs() = 0;
    virtual std::shared_ptr<Computer> Build() = 0;
};

//建造者的抽象类
class HuaweiBuilder : public Builder
{
public:
    HuaweiBuilder()
    : _com(new HuaweiComputer)
    {}
    void BuildScree(const std::string &scree) override
    {
        _com->Scree(scree);
    }
    void BuildBoard(const std::string &board) override
    {
        _com->Board(board);
    }
    void BuildOs() override
    {
        _com->Os();
    }
    std::shared_ptr<Computer> Build() override
    {
        return _com;
    }

private:
    std::shared_ptr<Computer> _com;
};

//指挥者类
class Cammander
{
public:
    Cammander(Builder* build)
    :_builder(build)
    {}
    void construct(const std::string& scree, const std::string& board)
    {
        _builder->BuildScree(scree);
        _builder->BuildBoard(board);
        _builder->BuildOs();
    }

private: 
    std::shared_ptr<Builder> _builder;
};

int main()
{
    Builder *builder = new HuaweiBuilder;
    std::unique_ptr<Cammander> cammander = std::make_unique<Cammander>(builder);
    cammander->construct("三星", "麒麟");
    std::shared_ptr<Computer> computer = builder->Build();
    computer->Display();

    return 0;
}